﻿<%@ page language="java" import="java.util.*,cn.ac.cintcm.dataconverge.researchsubject.domain.*" pageEncoding="UTF-8"%>
<%@page import="com.hs.core.page.PageUtil,com.hs.core.utils.*"%>
<%@page import="cn.ac.cintcm.dataconverge.util.Constants"%>
<%@page import="cn.ac.cintcm.dataconverge.researcher.domain.Researcher;"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
PageUtil pageUtil = (PageUtil)request.getAttribute("myjoibsubjectList");
List resultList = null;
String pageStr = ""; 
int perpageCount = 1;
int currentPage = 1;
if(null != pageUtil){
   resultList = pageUtil.getPageList();
   pageStr = pageUtil.getPageStr();
   perpageCount = pageUtil.getNumberPerPage();
   currentPage = pageUtil.getCurrentPage();
}
String subjectname = (String)request.getAttribute("subjectname");
String startdate = (String)request.getAttribute("startdate");
String enddate = (String)request.getAttribute("enddate");
String startyear = (String)request.getAttribute("startyear");
String endyear = (String)request.getAttribute("endyear");
String snumber = (String)request.getAttribute("snumber");
String status = (String)request.getAttribute("status");
String orderName = (String)request.getAttribute("orderName");
String orderNum = (String)request.getAttribute("orderNum"); 

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>课题信息</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    <link href="<%=path%>/index/Themes/com/style.css" rel="stylesheet" type="text/css" /> 
    <script src="<%=path%>/index/Scripts/Script.js" language="javascript" type="text/javascript"></script>
     <script src="<%=path%>/js/common.js" language="javascript" type="text/javascript"></script>
      
       <script src='<%=basePath%>dwr/engine.js'></script>
     <script src='<%=basePath%>dwr/util.js'></script> 
     <script src='<%=basePath%>dwr/interface/subject.js'></script>
    <script language="javascript" type="text/javascript" src="<%=path %>/js/My97DatePicker/WdatePicker.js"></script>
    <script language="javascript" type="text/javascript">
       /**function delSubject(id){
       		if(null != id && id != '' ){
       		 	if(confirm("确认删除课题?")){
       		 		form1.action = '<%=path%>/subjectToAdd.htm?action=delSubject&id='+id;
       		 		form1.submit();
       		 	}
       		}
       
       }*/
       function delSubject(id){
       		if(null != id && id != '' ){
       		 	if(confirm("确认删除课题?")){
       		 	    subject.delSubject(id,callbackForDelete);
       		 		//form1.action = '<%=path%>/subjectToAdd.htm?action=delAdminSubject&id='+id;
       		 		//form1.submit();
       		 		 
       		 	}
       		}
       
       }
       function callbackForDelete(message){
          if(message == "0")
             alert("删除课题失败");
          if(message == "1"){
               pageForm.submit();
          }
       }
       function searchSubject(){ 
       	
       			searchform.submit();			
       }
        var selectSubjectId = '';
       function submitAudit(subjectId){
          if(confirm('课题提交审批后将不能修改，确认提交?')){
	          if('' != subjectId){
	          	subject.submitAudit(subjectId,submitCallback)
	            selectSubjectId = subjectId;
	          }  
	      }
       }
       function submitCallback(message){
         if("0" == message){
            alert("课题提交审批失败");
         }
          if("1" == message){
            document.getElementById('status_' + selectSubjectId).innerHTML='申报中';
            document.getElementById('oper_' + selectSubjectId).innerHTML='';
             document.getElementById('edit_' + selectSubjectId).innerHTML='';
            document.getElementById('del_' + selectSubjectId).innerHTML='';
            alert("课题提交审批成功");
         }
       }
    </script>

</head>
<body class="rtm_body" scroll=yes>
<form name="searchform" action = "<%=path%>/subject.htm?action=listMyJoinedSubjects" method="post">
    <div class="r_rtm_tb_mg1">
        <div class="r_rtm_tb1">
            <span>
                <img src="<%=path%>/index/Themes/com/idt_tb_pass.gif" />&nbsp;&nbsp;参与的课题</span>
        </div>
    </div>   
     <table cellspacing="2" cellpadding="0" width="100%" class="idt_item_mg" id="Table2">
       <tr>
            <td class="fim_l" width="8%">
                课题名称：</td>
            <td class="fim_r" width="15%">
                <input type="text" name="subjectname" value="<%=subjectname==null?"":subjectname %>" class="com_textbox" ></td>
            <!-- td class="fim_l">
                申报日期：</td>
            <td class="fim_r" nowrap width="30%">
                从
               <input type="text" class="Wdate" id="startdate" value="<%=startdate==null?"":startdate %>" style="width:40%" name="startdate"  onFocus="WdatePicker({el:'startdate',dateFmt:'yyyy-MM-dd'})" />
                &nbsp;至
               <input type="text" class="Wdate" id="enddate" value="<%=enddate==null?"":enddate %>" style="width:40%" name="enddate"  onFocus="WdatePicker({el:'enddate',dateFmt:'yyyy-MM-dd'})" />
            </td-->
            <td class="fim_l" width="8%">
                课题编号：</td>
            <td class="fim_r" width="15%">
                <input type="text" class="com_textbox" id="snumber" value="<%=snumber==null?"":snumber %>" name="snumber"></td>
            <td class="fim_l" width="8%">
                所属年份：</td>
            <td class="fim_r" width="25%">
                从
               <input type="text" class="Wdate" id="startyear" value="<%=startyear==null?"":startyear %>" style="width:40%" name="startyear"  onFocus="WdatePicker({el:'startyear',dateFmt:'yyyy'})" />
                &nbsp;至
               <input type="text" class="Wdate" id="endyear" value="<%=endyear==null?"":endyear %>" style="width:40%" name="endyear"  onFocus="WdatePicker({el:'endyear',dateFmt:'yyyy'})" />
            </td> 
            <td class="fim_l" width="8%">
                课题状态：</td>
            <td class="fim_r" nowrap width="20%">
               <select name="status" style="width:100%">
                 <option value="-1">----请选择----</option>
                <option value="<%=Constants.subject_state_save%>" <%if((""+Constants.subject_state_save).equals(status)){out.println(" selected");} %>>未提交审批</option>
                 <option value="<%=Constants.subject_state_apply%>" <%if((""+Constants.subject_state_apply).equals(status)){out.println(" selected");} %>>申报中</option>
                  <option value="<%=Constants.subject_state_advised%>" <%if((""+Constants.subject_state_advised).equals(status)){out.println(" selected");} %>>推荐中标</option>
                   <option value="<%=Constants.subject_state_checked%>" <%if((""+Constants.subject_state_checked).equals(status)){out.println(" selected");} %>>中标</option>
                  <option value="<%=Constants.subject_state_researching%>" <%if((""+Constants.subject_state_researching).equals(status)){out.println(" selected");} %>>在研</option>
                 <option value="<%=Constants.subject_state_endApply%>" <%if((""+Constants.subject_state_endApply).equals(status)){out.println(" selected");} %>>申请结题</option>
                
                   <option value="<%=Constants.subject_state_ended%>" <%if((""+Constants.subject_state_ended).equals(status)){out.println(" selected");} %>>已结题</option>
                   <option value="<%=Constants.subject_state_unchecked%>" <%if((""+Constants.subject_state_unchecked).equals(status)){out.println(" selected");} %>>未中标</option>
                   <option value="<%=Constants.subject_state_retuen%>" <%if((""+Constants.subject_state_retuen).equals(status)){out.println(" selected");} %>>退回修改</option>
                 
                </select>  
            </td>
             <td class="fim_r" align="right" width="8%">
                <input type="submit" value="查询"  onclick="searchSubject()" class="com_btn2" id="Button5">
                 
                
            </td>
        </tr>
        </form>
    </table> 
   
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
            <td>
                <div class="content">
                 <form name="form1" action="" method="post">
                    <table width="*" cellpadding="0" cellspacing="1" class="dg_borderstyle" id="Table4">
                        <tr>
                            <td class="dg_headerstyle" width="5%">
                                序号</td>
                           <td class="dg_headerstyle" width="8%">
                                 <a href="javaScript:orderPage('snumber','<%=OrderTool.getOrderNum("snumber",orderName,orderNum)%>');">课题编号&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("snumber",orderName,orderNum))%></a></td>
                            <td class="dg_headerstyle" width="20%">
                                <a href="javaScript:orderPage('subjectname','<%=OrderTool.getOrderNum("subjectname",orderName,orderNum)%>');">课题名称&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("subjectname",orderName,orderNum))%></a></td>
                            <td class="dg_headerstyle" width="8%">
                                 <a href="javaScript:orderPage('state','<%=OrderTool.getOrderNum("state",orderName,orderNum)%>');">当前状态&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("state",orderName,orderNum))%></a></td>
                                   <td class="dg_headerstyle">
                                课题负责人</td>
                            <td class="dg_headerstyle">
                                牵头单位</td>
                            <td class="dg_headerstyle">
                                课题来源</td>
                                 
                            <td class="dg_headerstyle" width="10%">
                                 <a href="javaScript:orderPage('startdate','<%=OrderTool.getOrderNum("startdate",orderName,orderNum)%>');">计划开始日期&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("startdate",orderName,orderNum))%></a></td>
                                  <td class="dg_headerstyle" width="10%">
                                 <a href="javaScript:orderPage('enddate','<%=OrderTool.getOrderNum("enddate",orderName,orderNum)%>');">计划结束日期&nbsp;&nbsp;<%=OrderTool.getOrderImage(basePath,OrderTool.getOrderNum("enddate",orderName,orderNum))%></a></td>
                                
                                 <td class="dg_headerstyle">
                                查看</td>
                           <td class="dg_headerstyle">
                                修改</td>
                            <td class="dg_headerstyle">
                                删除</td>
                                <td class="dg_headerstyle">
                                提交审批</td> 
                        </tr>
                        <%if(null != resultList && resultList.size()> 0){
                            for(int i = 0;i < resultList.size();i++){
                                    Subject obj = (Subject)resultList.get(i); 
                                    boolean flag = false;
                               	 Researcher researcher = (Researcher) request.getSession().getAttribute(
                       				Constants.USER_IN_SESSION);
                               	 if(null != obj.getSubRes()){
                               		 Set set = obj.getSubRes();
                               		 if(null != set ){
                               			 Iterator iter = set.iterator();
                               			 while(iter.hasNext()) {
                               				 SubRes sr = (SubRes)iter.next();
                               				 Researcher re = sr.getRes();
                               				 if(null != re && (re.getIds()+"").equals(researcher.getIds()+"")){
   	                            				 if(null != sr && "1".equals(sr.getIsModify()+"")){
   	                            					 flag = true;
   	                            					 break;
   	                            				 }
                               				 }
                               			 }
                               		 }
                               			 
                               	 }
                                    boolean resultFlag = false;
                                    boolean isEdit = false;
                               	 if(Constants.subject_state_retuen.equals(obj.getState())||Constants.subject_state_save.equals(obj.getState()))
                                 	   isEdit = true;
                               	 if(flag && isEdit)
                               		 resultFlag = true;
                         %>
                        
                        <tr class="dg_alternatingitemstyle" onmouseover="ChangeRowBg(this);" onmouseout="ChangeRowBg(this);" onmouseup="ChangeRowBg(this);" onmousedown="ChangeRowBg(this);">
                            <td align="center" width="3%"><%= perpageCount*(currentPage-1)+i+1 %></td>
                            <td align="center" width="4%">
                             <%=StringUtilTool.NULL2Blank(obj.getSnumber()) %>
                            </td>
                            <td width="13%">
                                 <%if(flag){ %>
                                  <a href="#"   onclick="openwindow('<%=path %>/subjectToAdd.htm?action=viewSubject&id=<%=obj.getId() %>','','','')"> <%=StringUtilTool.NULL2Blank(obj.getSubjectname()) %></a>
                                  <%}else{ %>
                                  <%=StringUtilTool.NULL2Blank(obj.getSubjectname()) %>
                                  <%} %>
                            </td>
                            <td align="center" width="4%">
                                <font color="red"><span id="status_<%=obj.getId() %>"><%=Constants.getSubjectStatus(obj.getState()) %></span></font>
                            </td>
                             
                            <td width="13%">
                                 <%
                                   if(obj != null){
                                     Set res = obj.getSubRes();
                                     Iterator it = res.iterator();
                                     int j = 0;
                                     while(it.hasNext()){
                                    	
                                         SubRes rearcher = (SubRes)it.next();
                                         if(Constants.researcher_role_chargeman.equals(rearcher.getResRole()+"")){
                                        	 j++;
                                        	 out.println(rearcher.getRes()==null?"":rearcher.getRes().getName()+"&nbsp;"); 
                                         }
                                        // if(j>1)
                                        //	 out.println(",");
                                     }
                                   } 
                                 %>
                            </td>
                            <td width="13%">
                                <%
                                   if(obj != null){
                                     Set orgs = obj.getSubOrg();
                                     if(null != orgs){
	                                     Iterator it = orgs.iterator();
	                                     int h = 0;
	                                     while(it.hasNext()){
	                                         SubOrg org = (SubOrg)it.next(); 
	                                         if(Constants.org_role_leader.equals(org.getOrgRole()+"")){
	                                        	 out.println(org.getOrg()==null?"":org.getOrg().getName()+"&nbsp;"); 
	                                          	h++;
	                                          }
	                                         //if(h>1)
	                                        //	 out.println(",");
	                                     }
                                     }
                                   } 
                                 %>
                            </td>
                            <td width="13%">
                                 <%
                                   if(obj != null){
                                     Set tags = obj.getTags();
                                     Iterator ittag = tags.iterator();
                                     while(ittag.hasNext()){
                                    	 SubTag tag = (SubTag)ittag.next();
                                         if(null != tag && tag.getTag() != null && tag.getTag().getTagType() == 1)
                                         	out.println( tag.getTag().getName());
                                     }
                                   } 
                                 %>
                            </td>
                            
                            <td align="center" width="6%">
                                <%=Tools.getDateStringByDate1(obj.getStartdate() ) %>
                            </td> 
                            <td align="center" width="6%">
                                 <%=Tools.getDateStringByDate(obj.getEnddate()) %>
                            </td> 
                            
                           
                             <td align="center">
                             <%if(flag){ %>
                                  <a href="#"   onclick="openwindow('<%=path %>/subjectToAdd.htm?action=viewSubject&id=<%=obj.getId() %>','','','')"><img src="<%=path %>/index/Themes/com/zoom_16x16.gif" alt="查看"  style="cursor:hand" /></a>
                                  <%}else{ %>
                                  
                                  &nbsp;
                                  <%} %>
                            </td> 
                            <td align="center">
                               <%if(resultFlag){ %>
                               <span id ="edit_<%=obj.getId() %>"> <a href="<%=path %>/subjectToAdd.htm?action=modifySubject&subjectId=<%=obj.getId()%>&url=joinsubject"><img src="<%=path %>/index/Themes/com/68design.net_registration1_(edit)_16x16.gif" cursor="hand" alt="编辑" /> </a></span>
                               <%} %>
                            </td>
                            <td align="center">
                            <%if(resultFlag){ %>
                                  <span id ="del_<%=obj.getId() %>"> <img src="<%=path %>/index/Themes/com/68design.net_registration1_(delete)_16x16.gif" onclick="javascript:delSubject('<%=obj.getId() %>')"  style="cursor:hand" alt="删除" /></span>
                                  <%} %>
                            </td> 
                             <td align="center">
                             <%if(resultFlag){ %>
                              <span id ="oper_<%=obj.getId() %>"> <img src="<%=path %>/index/Themes/com/68design.net_registration1_(edit)_16x16.gif" alt="提交审批"  style="cursor:hand" onclick="javaScript:submitAudit('<%=obj.getId() %>')"/></span>
                              <%}else{ %>
                               &nbsp;
                              <%} %> 
                            </td>
                        </tr> 
                        <%}}else{%>
                         <tr class="dg_alternatingitemstyle"> 
                            <td align="center" colspan=14>
                                <font color="red">没有找到记录</font>
                            </td> 
                        </tr> 
                        <%}%>
                    </table>
                    </form> 
 						<div class="dg_pagerstyle" align="right"> 
                            <%=pageStr %>  
                    </div>   
                </div>
            </td>
        </tr>
    </table>
</body>
</html>